﻿<UserControl x:Class="IBTrader.Frontend.DailyTickData.Control"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:ctrlConn="clr-namespace:IBTrader.Frontend.Connection"
             xmlns:ctrlLog="clr-namespace:IBTrader.Frontend.Log"
             xmlns:my="clr-namespace:IBTrader.Frontend.DailyTickData">

    <UserControl.DataContext>
        <my:ViewModel/>
    </UserControl.DataContext>
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\ResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction Command="{Binding LoadedCommand}" 
                                   CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="Closing" SourceObject="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
            <i:InvokeCommandAction Command="{Binding UnloadedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <DockPanel LastChildFill="True">
        <Menu DockPanel.Dock="Top" Height="22">
            <ctrlConn:Menu />
            <ctrlLog:Menu />
        </Menu>
        <ctrlLog:Errors DockPanel.Dock="Top" />
        <ctrlLog:Status DockPanel.Dock="Bottom" Height="22" />
        <ScrollViewer>
            <StackPanel Orientation="Vertical">
                <WrapPanel>
                    <Button Content="Start / Restart" Command="{Binding Start}" Margin="5" Padding="5"/>
                </WrapPanel>
                <Expander Header="Connection">
                    <ctrlConn:Control />
                </Expander>
                <Expander Header="Contracts" IsExpanded="True">
                    <DataGrid ItemsSource="{Binding Path=Store.Contracts, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Symbol" Binding="{Binding Symbol, UpdateSourceTrigger=PropertyChanged}" />
                            <DataGridComboBoxColumn Header="Exchange" IsReadOnly="False"
                                                    ItemsSource="{Binding Source={StaticResource Exchanges}}"
                                                    SelectedValueBinding="{Binding Exchange, UpdateSourceTrigger=PropertyChanged}"/>
                            <DataGridTextColumn Header="Currency" Binding="{Binding Currency, UpdateSourceTrigger=PropertyChanged}" />
                            <DataGridTextColumn Header="Expiry" Binding="{Binding Expiry, UpdateSourceTrigger=PropertyChanged}" />
                            <DataGridComboBoxColumn Header="SecurityType" 
                                                    ItemsSource="{Binding Source={StaticResource SecurityTypes}}"
                                                    SelectedValueBinding="{Binding SecurityType, UpdateSourceTrigger=PropertyChanged}"/>
                            <DataGridTextColumn Header="Multiplier" Binding="{Binding Multiplier, UpdateSourceTrigger=PropertyChanged}" />
                            <DataGridTextColumn Header="MinTick" Binding="{Binding MinTick, UpdateSourceTrigger=PropertyChanged}" />
                            <DataGridTextColumn Header="PrimaryExchange" Binding="{Binding PrimaryExchange, UpdateSourceTrigger=PropertyChanged}" />
                            <DataGridCheckBoxColumn Header="Requested" Binding="{Binding ReqEnd}" IsReadOnly="True" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Expander>
                <Expander Header="Log" IsExpanded="True">
                    <ctrlLog:Control />
                </Expander>                
            </StackPanel>
        </ScrollViewer>
    </DockPanel >
</UserControl>